<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
 <style>
        body {
            font-family: Arial, sans-serif;
        }
        .search-form {
            margin: 20px 0;
        }
        .search-form input[type="text"] {
            padding: 8px;
            font-size: 16px;
            border: 1px solid #ccc;
            border-radius: 4px;
            width: 300px;
        }
        .search-form input[type="submit"] {
            padding: 8px 15px;
            background-color: #4CAF50; /* 绿色背景 */
            color: white;
            border: none;
            border-radius: 4px;
            cursor: pointer;
        }
        .search-form input[type="submit"]:hover {
            background-color: #45a049; /* 较深的绿色，用于鼠标悬浮效果 */
        }
        table {
            width: 80%;
            margin-top: 20px;
            border-collapse: collapse;
            border: 1px solid #4CAF50; /* 绿色边框 */
        }
        th, td {
            padding: 10px;
            text-align: left;
            border: 1px solid #4CAF50; /* 绿色边框 */
        }
        th {
            background-color: #4CAF50; /* 绿色背景 */
            color: white; /* 白色文字 */
        }
    </style>
<body>
 <%
//接收数据kw
request.setCharacterEncoding("utf-8");
String key = request.getParameter("kw");
if(key==null){
	key="";
}
%>
    <div class="search-form">
        <form method="post">
            请输入查询条件: <input type="text" name="kw" value="<%=key%>"/>
            <input type="submit" value="查询"/>
        </form>
    </div>
  <%  
if(key.length()>0){
    

//构造sQL
String sql = "SELECT * FROM restaurants WHERE name like '%"+key+"%' or address LIKE'%"+key+"%'";
//out.println(sql);
//out.println("<br>");

//查询DB---->rs
/*Class.forName("org.mariadb.jdbc.Driver");
Connection connection = DriverManager.getConnection("jdbc:mariadb://10.220.140.102:3366/studb11","stua","zHZUA65r");
Statement stmt = connection.createStatement();
ResultSet rs = stmt.executeQuery(sql);
*/
//sql--->rs

javax.sql.rowset.WebRowSet rs = aa.db.DBTools.getRS(sql);



//显示rs结果
out.println("<table width='80%' border='1'>");
out.println("<tr><th>餐馆名</th><th>地址</th></tr>");
while (rs.next()){
	out.println("<tr>");
	out.println("<td>"+rs.getString("name")+"</td>");
	out.println("<td>"+rs.getString("address")+"</td>");

	
	out.println("</tr>");
}
out.println("</table>");
rs.close();


}
%>
</body>
